#include "dockwidget.h"
#include <QBoxLayout>

void UDockChild::mouseReleaseEvent(QMouseEvent *event)
{
    emit mouseUp(event);
}


void UDockChild::mousePressEvent(QMouseEvent *event)
{
    emit mouseDown(event);
}

void UDockChild::mouseMoveEvent(QMouseEvent *event)
{
    emit mouseMove(event);
}

static int counter = 0;

UDockChild::UDockChild(QWidget *parent, Qt::WindowFlags flags):QWidget(parent,flags){

    this->setLayout(new QHBoxLayout());
    this->layout()->addWidget(new QLabel(QString().sprintf("text %d", counter++)));
}


void UDockChild::keyPressEvent(QKeyEvent *event)
{
    emit keyPress(event);
}



UDockWidget::UDockWidget(QWidget *parent, Qt::WindowFlags flags):QDockItem(parent,flags){
    this->setLayout(new QHBoxLayout());
    UDockChild* child = new UDockChild();
    connect(child,SIGNAL(mouseDown(QMouseEvent*)),this,SLOT(mouseDownSlot(QMouseEvent*)));
    connect(child,SIGNAL(mouseUp(QMouseEvent*)),this,SLOT(mouseUpSlot(QMouseEvent*)));
    connect(child,SIGNAL(mouseMove(QMouseEvent*)),this,SLOT(mouseMoveSlot(QMouseEvent*)));
    connect(child,SIGNAL(keyPress(QKeyEvent*)),this,SLOT(keyPressSlot(QKeyEvent*)));
    this->layout()->setMargin(0);
    this->layout()->addWidget(child);
}

void UDockWidget::keyPressEvent(QKeyEvent *event)
{
    emit keyPress(this,event);
}

void UDockWidget::mouseDownSlot(QMouseEvent *event)
{
    emit mouseDown(this,event);
}

void UDockWidget::mouseMoveSlot(QMouseEvent *event)
{
    emit mouseMove(this,event);
}

void UDockWidget::mouseUpSlot(QMouseEvent *event)
{
    emit mouseUp(this,event);
}

void UDockWidget::keyPressSlot(QKeyEvent *event)
{
    emit keyPress(this,event);
}


